<template>
    <div class="app-container">
        <div class="block">
            <el-row :gutter="20">
                <el-col :span="6">
                    <el-input v-model="listQuery.criteria.goodsName" size="mini" placeholder="商品名称"></el-input>
                </el-col>
                <el-col :span="6">
                    <el-select v-model="listQuery.criteria.goodsType" size="mini" placeholder="商品类型">
                        <el-option label="全部" value=""></el-option>
                        <el-option v-for="item in goodsTypeList" :key="item.id" :label="item.name"
                            :value="item.num"></el-option>
                    </el-select>
                </el-col>
                <el-col :span="6">
                    <el-button type="success" size="mini" icon="el-icon-search" @click.native="search">搜索</el-button>
                    <el-button type="primary" size="mini" icon="el-icon-refresh" @click.native="reset">重置</el-button>
                </el-col>
            </el-row>
            <br>
            <el-row>
                <el-col :span="24">
                    <el-button type="success" size="mini" icon="el-icon-plus" @click.native="add">添加</el-button>
                </el-col>
            </el-row>
        </div>



        <el-row>
            <el-col :span="20">
                <el-table :data="list" v-loading="listLoading" element-loading-text="Loading" border fit
                    highlight-current-row @current-change="handleCurrentChange">

                    <el-table-column label="商品名称" :span="4">
                        <template slot-scope="scope">
                            {{ scope.row.goodsName }}
                        </template>
                    </el-table-column>
                    <el-table-column label="商品类型" :span="4">
                        <template slot-scope="scope">
                            {{ getTypeValueDict(scope.row.goodsType)}}
                        </template>
                    </el-table-column>
                    <el-table-column label="商品规格" :span="4">
                        <template slot-scope="scope">
                            <el-tag :key="tag" v-for="tag in scope.row.specification" size="mini">
                                {{ tag }}
                            </el-tag>
                        </template>
                    </el-table-column>

                    <el-table-column label="商品价格" :span="4">
                        <template slot-scope="scope">
                            {{ scope.row.price/100 }}元{{ scope.row.priceUnit }}
                        </template>
                    </el-table-column>

                    <el-table-column label="单位容量" :span="4">
                        <template slot-scope="scope">
                            {{ scope.row.capacity }}
                        </template>
                    </el-table-column>

                    <el-table-column label="排序" :span="4">
                        <template slot-scope="scope">
                            {{ scope.row.num }}
                        </template>
                    </el-table-column>

                    <el-table-column label="操作" min-width="50px" :span="4">
                        <template slot-scope="scope">
                            <el-button type="text" size="mini" icon="el-icon-edit"
                                @click.native="editItem(scope.row)">修改</el-button>
                            <el-button  type="text"
                                size="mini" icon="el-icon-delete" @click.native="removeItem(scope.row.id)">删除</el-button>
                        </template>

                    </el-table-column>




                </el-table>

                <el-pagination background layout="total, sizes, prev, pager, next, jumper"
                    :page-sizes="[10, 20, 50, 100, 500]" :page-size="listQuery.size" :total="total"
                    :current-page.sync="listQuery.current" @size-change="changeSize" @current-change="fetchPage"
                    @prev-click="fetchPrev" @next-click="fetchNext">
                </el-pagination>

            </el-col>
        </el-row>




        <el-dialog :title="formTitle" :visible.sync="formVisible" width="50%">
            <el-form ref="form" :model="form" :rules="rules" label-width="120px" label-position="right">
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="商品名称" prop="goodsName">
                            <el-input v-model="form.goodsName" minlength=1></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="商品类型" prop="goodsType">
                            <el-select v-model="form.goodsType" placeholder="选择商品类型">
                                <el-option v-for="item in goodsTypeList" :key="item.id" :label="item.name"
                                    :value="item.num">
                                </el-option>
                            </el-select>
                        </el-form-item>

                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="商品单价" prop="capacity">
                            <el-input-number  v-model="form.price" :min="1"></el-input-number>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="计量单位" prop="capacity">
                            <el-input  v-model="form.priceUnit" ></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="单位容量" prop="capacity">
                            <el-input-number  v-model="form.capacity" :min="0"></el-input-number>
                        </el-form-item>
                    </el-col>

                    <el-col :span="12">
                        <el-form-item label="排序" prop="num">
                            <el-input-number v-model="form.num" :min="1"></el-input-number>
                        </el-form-item>
                    </el-col>

                    <el-col :span="12">
                        <el-form-item label="商品规格" prop="specification">
                            <el-tag :key="tag" v-for="tag in form.specification" closable :disable-transitions="false"
                                @close="handleClose(tag)">
                                {{ tag }}
                            </el-tag>
                            <el-input class="input-new-tag" v-if="inputVisible" v-model="inputValue" ref="saveTagInput"
                                size="small" @keyup.enter.native="handleInputConfirm" @blur="handleInputConfirm">
                            </el-input>
                            <el-button v-else class="button-new-tag" size="small" @click="showInput">+ </el-button>

                        </el-form-item>
                    </el-col>



                </el-row>
                <el-form-item>
                    <el-button type="primary" @click="save">提交</el-button>
                    <el-button @click.native="formVisible = false">取消</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>


        <el-dialog title="规格修改" :visible.sync="formUpdateVisible" width="50%">
            <el-form :model="formUpdate"  label-width="120px" label-position="right">
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="单位容量" prop="capacity">
                            <el-input-number  v-model="formUpdate.capacity" :min="0"></el-input-number>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="排序" prop="num">
                            <el-input-number  v-model="formUpdate.num" :min="1"></el-input-number>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-form-item>
                    <el-button type="primary" @click="update">提交</el-button>
                    <el-button @click.native="formUpdateVisible = false">取消</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>





    </div>
</template>

<script src="./goodscapacity.js">
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";

.button-new-tag {
    margin-left: 10px;
    height: 32px;
    line-height: 30px;
    padding-top: 0;
    padding-bottom: 0;
}

.input-new-tag {
    width: 90px;
    margin-left: 10px;
    vertical-align: bottom;
}
</style>
